<?php
$ImageChecker->setBackupImage($loc . "images/staticbackups/notfound146x106.png");
if (!$XMLInstance) {

    function __autoload($class_name) {
        require_once "../web3g/inc/" . $class_name . ".inc.php";
    }

    $XMLInstance = new OutputXML('web3g/xml/products.xml');
}

function subval_sort($a, $subkey, $sort) {
    foreach ($a as $k => $v) {
        $b[$k] = strtolower($v[$subkey]);
    }
    $sort($b);
    foreach ($b as $key => $val) {
        $c[] = $a[$key];
    }
    return $c;
}

$cnt = 1;
unset($tpl);
unset($mc);
unset($sc);
unset($pd);
if ($_REQUEST['c'])
    $tpl = $CleanCode->Decode($_REQUEST['c']);
$MasterCat = $XMLInstance->GetMasterCategories($tpl);
foreach ($MasterCat as $mc) {
    if ($_REQUEST['mc'])
        $mc = $CleanCode->Decode($_REQUEST['mc']);
    $SubCat = $XMLInstance->GetSubCategories($tpl, $mc);
    foreach ($SubCat as $sc) {
        if ($_REQUEST['sc'])
            $sc = $CleanCode->Decode($_REQUEST['sc']);
        $products = $XMLInstance->GetProducts($tpl, $mc, $sc);

        $products = subval_sort($products, 'OurPrice', $_SESSION['itemOrder']); //asort for ASC and arsort for DEC
        foreach ($products as $pd) {
            if (
                    ($searchby == "brand" && strtolower($pd['Brand']) == $innerif[0]) ||
                    ($searchby == "price" && $pd['OurPrice'] > $innerif[0] && $pd['OurPrice'] < $innerif[3]) ||
                    !isset($innerif)
            ) {
                if ($cnt >= $StartItem) {
                    // Break info into its two parts, features and specifications
                    $prod_info = explode("****", $pd['Description']);
?>							<div class="product">
                <div class="productimg">
                    <a href="/moreinfo/<?php echo $pd['StockCode'] ?>/<?php echo $CleanCode->Encode($tpl) ?>/">
            <?php $ImageChecker->showImg("/web3g/img/accessories/" . $pd['StockCode'] . ".jpg", "146", "106", $pd['Name'], "", ""); ?>
                </a>
            </div>
            <div class="productDesc">
<?php
                    //truncate title
                    $title_limit = 55;
                    if (strlen($pd['Name']) > $title_limit) {
                        $current_title = substr($pd['Name'], 0, strpos($pd['Name'], " ", 60)) . "...";
                    } else {
                        $current_title = $pd['Name'];
                    }
?>
                    <a href="/moreinfo/<?php echo $pd['StockCode'] ?>/<?php echo $CleanCode->Encode($tpl) ?>/"><h3><?php echo $current_title; ?></h3></a><br />
                    <div><?php echo substr($prod_info[0], 0, 200); ?>...<?php /* ?><br /><br />
                      <img src="/images/item/item_delivicon.png" style="vertical-align:middle;" /><span class="freedelivery">FREE DELIVERY</span><?php */ ?>
                    </div>
                </div>
                <div class="productPrice">
                    <img src="/images/spacer.gif" width="100%" height="15" />
<?php /* ?><span class="rrp"><?php if($pd['RRP'] > 0){ ?>Was &pound;<?php echo number_format($pd['RRP'])?><?php } ?></span><?php */ ?>
                    <br /><span class="price">&euro;<?php echo number_format($pd['OurPrice'], 2); ?></span>
<?php /* ?><br /><span class="saving"><?php if($pd['RRP'] > 0){ ?>Save <?php echo $pd['Saving']?><? } ?></span><?php */ ?>
                    <img src="/images/spacer.gif" width="100%" height="10" />
                    <img src="/images/item/item_hline_01.jpg" />
                    <img class="productSpacerLast" src="/images/spacer.gif" width="100%" height="10" />
                    <a href="/moreinfo/<?php echo $pd['StockCode'] ?>/<?php echo $CleanCode->Encode($tpl) ?>/">
                                <img src="/images/spacer.gif" class="spritebg infoBtn" />
                            </a>
                            <form action="/basket/" method="post" style="display:inline-block;">
                                <input type="hidden" name="esid" value="<?php echo $_SESSION['esid']; ?>" />
                                <input type="hidden" name="acid" value="<?php echo $pd['StockCode'] ?>" />
                                <input type="image" src="/images/spacer.gif" class="spritebg buyBtn" />
                            </form>
                        </div>
                    </div>
                    <img class="productBottomShadow" src="/images/item/item_btmshad.gif" width="763" height="5" style="float:left;" />
                    <div style="height:10px; width:100%; display:block; float:left; clear:both;">&nbsp;</div>
<?php
                } $cnt++;
            } if ($cnt == $EndItem + 1) {
                break(3);
            }
        }
        if ($_REQUEST['sc'])
            break;
    }
    if ($_REQUEST['mc'])
        break;
}
?>